home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / unzip51 / amiga / amiga.c next >
Encoding:
C/C++ Source or Header  |  1992-10-20  |  4.1 KB  |  127 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   amiga.c
  4.  
  5.   Amiga-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  6.  
  7.   ---------------------------------------------------------------------------*/
  8.  
  9.  
  10. #include "unzip.h"
  11.  
  12. #ifndef S_ISCRIPT          /* not having one implies you have none */
  13. #  define S_IARCHIVE 0020  /* not modified since this bit was last set */
  14. #  define S_IREAD    0010  /* can be opened for reading */
  15. #  define S_IWRITE   0004  /* can be opened for writing */
  16. #  define S_IDELETE  0001  /* can be deleted */
  17. #endif
  18. #ifndef S_IRWD
  19. #  define S_IRWD     0015  /* useful combo of Amiga privileges */
  20. #endif
  21. #ifndef S_IHIDDEN
  22. #  define S_IHIDDEN  0200  /* hidden supported in future AmigaDOS 3.x */
  23. #endif
  24.  
  25.  
  26.  
  27. /**********************/
  28. /* Function mapattr() */
  29. /**********************/
  30.  
  31. int mapattr()      /* Amiga version */
  32. {
  33.     ulg  tmp = crec.external_file_attributes;
  34.  
  35.  
  36.     /* Amiga attributes = hsparwed = hidden, script, pure, archive,
  37.      * read, write, execute, delete */
  38.  
  39.     switch (pInfo->hostnum) {
  40.         case AMIGA_:
  41.             /* turn off archive bit for restored Amiga files */
  42.             pInfo->file_attr = (unsigned)((tmp>>16) & (~S_IARCHIVE));
  43.             break;
  44.  
  45.         case UNIX_:   /* preserve read, write, execute:  use logical-OR of */
  46.         case VMS_:    /* user, group, and other; if writable, set delete bit */
  47.             tmp >>= 16;
  48.             tmp = (( tmp>>6 | tmp>>3 | tmp) & 07) << 1;
  49.             pInfo->file_attr = (unsigned)(tmp&S_IWRITE? tmp|S_IDELETE : tmp);
  50.             break;
  51.  
  52.         /* all other platforms:  assume read-only bit in DOS half of attribute
  53.          * word is set correctly ==> will become READ or READ+WRITE+DELETE */
  54.         case FS_FAT_:
  55.         case FS_HPFS_:  /* can add S_IHIDDEN check to MSDOS/OS2/NT eventually */
  56.         case FS_NTFS_:
  57.         case MAC_:
  58.         case ATARI_:
  59.         case TOPS20_:
  60.         default:
  61.             pInfo->file_attr = (unsigned)(tmp&1? S_IREAD : S_IRWD); 
  62.             break;
  63.  
  64.     } /* end switch (host-OS-created-by) */
  65.  
  66.     pInfo->file_attr &= 0xff;   /* mask off all but lower eight bits */
  67.     return 0;
  68.  
  69. } /* end function mapattr() */
  70.  
  71.  
  72.  
  73.  
  74.  
  75. /**************************************/
  76. /* Function set_file_time_and_close() */
  77. /**************************************/
  78.  
  79. void set_file_time_and_close()
  80. {
  81.     static short yday[]={0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
  82.     long m_time;
  83.     int yr, mo, dy, hh, mm, ss, leap, days=0;
  84.     struct utimbuf {
  85.         time_t actime;          /* new access time */
  86.         time_t modtime;         /* new modification time */
  87.     } tp;
  88. #   define YRBASE  1978         /* in AmigaDos, counting begins 01-Jan-1978 */
  89.     struct DateStamp myadate;
  90.  
  91.  
  92.     if (cflag)                  /* can't set time on stdout */
  93.         return;
  94.  
  95.     /* close the file *before* setting its time under AmigaDos */
  96.     close(outfd);
  97.  
  98.     /* dissect MSDOS-format date and time */
  99.     yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + (1980 - YRBASE);
  100.     mo = ((lrec.last_mod_file_date >> 5) & 0x0f) - 1;
  101.     dy = (lrec.last_mod_file_date & 0x1f) - 1;
  102.     hh = (lrec.last_mod_file_time >> 11) & 0x1f;
  103.     mm = (lrec.last_mod_file_time >> 5) & 0x3f;
  104.     ss = (lrec.last_mod_file_time & 0x1f) * 2;
  105.  
  106.     /* leap = # of leap years from BASE up to but not including current year */
  107.     leap = ((yr + YRBASE - 1) / 4);   /* leap year base factor */
  108.  
  109.     /* How many days from BASE to this year? (& add expired days this year) */
  110.     days = (yr * 365) + (leap - 492) + yday[mo];
  111.  
  112.     /* if year is a leap year and month is after February, add another day */
  113.     if ((mo > 1) && ((yr+YRBASE)%4 == 0) && ((yr+YRBASE) != 2100))
  114.         ++days;   /* OK through 2199 */
  115.  
  116.     myadate.ds_Days   = days + dy - 2;   /* off by one? */
  117.     myadate.ds_Minute = hh*60 + mm;
  118.     myadate.ds_Tick   = ss*TICKS_PER_SECOND;
  119.  
  120.     if (!FileDate(filename, &myadate))
  121.         fprintf(stderr, "warning:  can't set the time for %s\n", filename);
  122.  
  123.     /* set file perms after closing (not done at creation)--see mapattr() */
  124.     chmod(filename, pInfo->file_attr);
  125.  
  126. } /* end function set_file_time_and_close() */
  127.